﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace BBPA.BLL
{
   public class Group_Good
    {
        private readonly BBPA.DAL.Group_Good dal = new BBPA.DAL.Group_Good();
        public Group_Good()
        { }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ggid)
        {
            return dal.Exists(ggid);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BBPA.Model.Group_Good model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(BBPA.Model.Group_Good model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ggid)
        {

            return dal.Delete(ggid);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string ggidlist)
        {
            return dal.DeleteList(ggidlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BBPA.Model.Group_Good GetModel(int ggid)
        {

            return dal.GetModel(ggid);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public BBPA.Model.Group_Good GetModelByCache(int ggid)
        {

            string CacheKey = "Group_GoodModel-" + ggid;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(ggid);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (BBPA.Model.Group_Good)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataTable GetList_dt(string column, string strWhere)
        {
            if (column == "") column = "id,OrdersID,GoodsID,ExpectAmount,gggoodprice as ExpectPrice,ExpectPriceSum,ActualAmount,ActualPrice,ActualPriceSum,IsAsExpect,Description,Dateandtime,Name,ShotrName,Code,SellPrice,IsPromo,IsOffShelf,CategoryName,BrandName,Number,SupplierName,SupplierNumber,PicURL,PicWidth,PicHeight,PicTitle,BuyPrice,ActualBuyPrice,ActualBuyPriceSum,ExpectBuyPrice,ExpectBuyPriceSum,ExpectPay,ActualPay,IsLatePay,ExpectDiscount,ExpectGiftNumber,ActualDiscount,ActualGiftNumber,ExpectBuyDiscount,ExpectBuyGiftNumber,ActualBuyDiscount,ActualBuyGiftNumber,HasBuy,SupplierShortName,SupplierID,ComeFrom,IsDelivery,Tel,Mobile,WaitSupplierCheckNum,HasCheck,HasCall4Delivery,storename,StoreID,storetel";
            DataSet ds = dal.GetList(column, strWhere);
            return ds.Tables[0];
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<BBPA.Model.V_Orders_Goods> GetList(string column, string strWhere)
        {
            if (column == "") column = "id,OrdersID,GoodsID,ExpectAmount,gggoodprice as ExpectPrice,ExpectPriceSum,ActualAmount,ActualPrice,ActualPriceSum,IsAsExpect,Description,Dateandtime,Name,ShotrName,Code,SellPrice,IsPromo,IsOffShelf,CategoryName,BrandName,Number,SupplierName,SupplierNumber,PicURL,PicWidth,PicHeight,PicTitle,BuyPrice,ActualBuyPrice,ActualBuyPriceSum,ExpectBuyPrice,ExpectBuyPriceSum,ExpectPay,ActualPay,IsLatePay,ExpectDiscount,ExpectGiftNumber,ActualDiscount,ActualGiftNumber,ExpectBuyDiscount,ExpectBuyGiftNumber,ActualBuyDiscount,ActualBuyGiftNumber,HasBuy,SupplierShortName,SupplierID,ComeFrom,IsDelivery,Tel,Mobile,WaitSupplierCheckNum,HasCheck,HasCall4Delivery";
            DataSet ds = dal.GetList(column,strWhere);
            return DataTableToList_V_Orders_Goods(ds.Tables[0]);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<BBPA.Model.V_Orders_Goods> DataTableToList_V_Orders_Goods(DataTable dt)
        {
            BBPA.DAL.V_Orders_Goods dal_V_Orders_Goods = new DAL.V_Orders_Goods();
            List<BBPA.Model.V_Orders_Goods> modelList = new List<BBPA.Model.V_Orders_Goods>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                BBPA.Model.V_Orders_Goods model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = dal_V_Orders_Goods.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetGroupBuy_GoodList(string strWhere)
        {
            return dal.GetGroupBuy_GoodList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<BBPA.Model.Group_Good> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<BBPA.Model.Group_Good> DataTableToList(DataTable dt)
        {
            List<BBPA.Model.Group_Good> modelList = new List<BBPA.Model.Group_Good>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                BBPA.Model.Group_Good model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = dal.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
    }
}
